import { storage, StorageKey } from "@/mdesign-lib/mdesign-app.umd.js";

/**
 * 自动校验模式
 */
export enum AutoValidModel {
  All = "all",
  System = "system"
}
/**
 * 最小严重程度
 */
export enum MinSeverity {
  Debugging = 1,
  Warn = 3,
  Tip = 2,
  Error = 4,
  Fatal = 5
}
export const defaultRuleValue = {
  isOpenAutoValidModel: false,
  autoValidModel: AutoValidModel.All,
  autoValidCycle: 60,
  isAutoValidRangVisible: true,
  isExcludeReadOnlyEle: true,
  minSeverity: 4
};
export const ruleOptions = [
  { label: "是否开启自动校验", type: "switch", key: "isOpenAutoValidModel" },
  {
    label: "自动校验模式",
    type: "select",
    key: "autoValidModel",
    options: [
      { label: "全部", value: AutoValidModel.All },
      { label: "系统内置", value: AutoValidModel.System }
    ]
  },
  { label: "自动校验周期", type: "number", key: "autoValidCycle" },
  { label: "自动校验范围仅为可见的图", type: "switch", key: "isAutoValidRangVisible" },
  { label: "排除已用只读项目中的元素", type: "switch", key: "isExcludeReadOnlyEle" },
  {
    label: "最小严重程度",
    type: "select",
    key: "minSeverity",
    options: [
      { label: "调试", value: MinSeverity.Debugging },
      { label: "提示", value: MinSeverity.Tip },
      { label: "警告", value: MinSeverity.Warn },
      { label: "错误", value: MinSeverity.Error },
      { label: "致命", value: MinSeverity.Fatal }
    ]
  }
];
export class ModelValidRule {
  /**
   * 默认校验配置
   */
  ruleValue = { ...defaultRuleValue };
  constructor() {
    // 读取全局的设置
    const modelValidConfig = storage.get(StorageKey.modelValidConfig);
    if (modelValidConfig) {
      console.log(" 加载中 modelValidConfig =", modelValidConfig);
      this.ruleValue = { ...modelValidConfig };
    }
  }
  handleReset() {
    this.ruleValue = { ...defaultRuleValue };
  }
  handleSave() {
    storage.set(StorageKey.modelValidConfig, { ...this.ruleValue });
  }
}
